package com.kkb.dao;
import com.kkb.pojo.Team;
import com.kkb.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class TeamDaoImpl implements TeamDao {
    @Override
    public List<Team> queryAll() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        List<Team> list = sqlSession.selectList("com.kkb.pojo.Team.queryAll");
        return list;
    }

    @Override
    public Team queryOne(Integer teamId) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        Team team = sqlSession.selectOne("com.kkb.pojo.Team.findById", teamId);
        return team;
    }

    @Override
    public Integer add(Team team) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        int insert = sqlSession.insert("com.kkb.pojo.Team.add", team);
        sqlSession.commit();
        sqlSession.close();
        return insert;
    }

    @Override
    public Integer update(Team team) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        int update = sqlSession.update("com.kkb.pojo.Team.update", team);
        sqlSession.commit();
        sqlSession.close();
        return update;
    }

    @Override
    public Integer delete(Integer teamId) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        int delete = sqlSession.delete("com.kkb.pojo.Team.delete", teamId);
        sqlSession.commit();
        sqlSession.close();
        return delete;
    }
}
